package com.wkk.nursinghome.dao;

import com.wkk.nursinghome.domain.Checkin;
import com.wkk.nursinghome.domain.Employee;
import org.apache.ibatis.jdbc.SQL;

public class CheckinSQLProvider {
    //动态语句执行修改
    public String updateCheckin(Checkin checkin){
        return new SQL(){
            {
                UPDATE("checkin");
                if(null!=checkin.getName()){
                    SET("name=#{name}");
                }
                if(null!=checkin.getSex()){
                    SET("sex=#{sex}");
                }
                if(null!=checkin.getAge()){
                    SET("age=#{age}");
                }
                if(null!=checkin.getIdcard()){
                    SET("idcard=#{idcard}");
                }
                if(null!=checkin.getRnumber()){
                    SET("rnumber=#{rnumber}");
                }
                if(null!=checkin.getBnumber()){
                    SET("bnumber=#{bnumber}");
                }
                if(null!=checkin.getFnumber()){
                    SET("fnumber=#{fnumber}");
                }
                if(null!=checkin.getCitime()){
                    SET("citime=#{citime}");
                }
                if(null!=checkin.getCetime()){
                    SET("cetime=#{cetime}");
                }
                if(null!=checkin.getCnumber()){
                    SET("cnumber=#{cnumber}");
                }
                if(null!=checkin.getFamily()){
                    SET("family=#{family}");
                }
                if(null!=checkin.getAccompany()){
                    SET("accompany=#{accompany}");
                }
                if(null!=checkin.getAssessmentdo()){
                    SET("assessmentdo=#{assessmentdo}");
                }
                if(null!=checkin.getChargedo()){
                    SET("chargedo=#{chargedo}");
                }
                if(null!=checkin.getCareworker()){
                    SET("careworker=#{careworker}");
                }
                if(null!=checkin.getHealthsteward()){
                    SET("healthsteward=#{healthsteward}");
                }
                if(null!=checkin.getOperator()){
                    SET("operator=#{operator}");
                }
                if(null!=checkin.getRemarks()){
                    SET("remarks=#{remarks}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }
    //根据条件查询信息
    public String selectCheckinByCondition(Checkin checkin){
        return new SQL(){
            {
                SELECT("*");
                FROM("checkin");
                //使用动态SQL拼接查询条件
                if(null!=checkin.getName()){
                    WHERE("name like concat('%',#{name},'%')");
                }
                if(null!=checkin.getIdcard()){
                    WHERE("idcard=#{idcard}");
                }
            }
        }.toString();
    }
}
